<template>
    <div>
        <h1>病房显示</h1>
        <a href="/AddBF">新增</a>
        <br>
        <a href="/Jump">目录</a>
        <br>
        科室:
        <select v-model="tiaoj.Ksid">
                            <option value="0">科室</option>
                            <option v-for="d in xiala" :value="d.DMid">{{ d.DMname }}</option>
                        </select>


        病房名称:
        <input type="text" v-model="tiaoj.RNname">
        <input type="button" value="查询" @click="xians()">
        <table class="table">
            <thead>
                <tr>
                    <td>病房号</td>
                    <td>病房名称</td>
                    <td>所属科室</td>
                    <td>床位总数量</td>
                    <td>状态</td>
                    <td>空闲床数量</td>
                    <td>创建日期</td>
                    <td>操作</td>
                </tr>
            </thead>
            <tbody v-for="d in data">
                <tr>
                    <td>{{d.Rnumber}}</td>
                    <td>{{d.RNname}}</td>
                    <td>{{d.DMname}}</td>
                    <td>{{d.bednum}}</td>
                    <td>{{d.USname}}</td>
                    <td>{{d.nobednum}}</td>
                    <td>{{d.Rtimes}}</td>
                    <td>
                        <input type="button" value="维修" @click="weixiu(d.Rid)">
                        <input type="button" value="启用" @click="qiy(d.Rid)">
                        <input type="button" :value="d.USname=='启用'?'维护':'启用'" @click="xiugai(d.Rid)">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { onMounted, ref } from 'vue';

onMounted(() => {
    xians();
    KSXL();
});
const tiaoj=ref({
    "Ksid":0,
    "RNname":""
})
const data = ref([{
    "Rid": 0,
    "Rnumber": "",
    "Ksid": 0,
    "bednum": 0,
    "states": 0,
    "nobednum": 0,
    "Rtimes": "2025-02-02T00:00:00",
    "RNname": "",
    "USid": 0,
    "USname": "",
    "DMid": 0,
    "DMname": ""
}])
const xians = ()=>{
    axios.get("https://localhost:7292/api/Room/ShowBF",{params:tiaoj.value}).then(res=>{
        data.value=res.data
    })
}
///////科室下拉//////////////
const xiala = ref([
    {
    "DMid": 0,
    "DMname": "",
  }
])
const KSXL = ()=>{
    axios.get("https://localhost:7292/api/Deparment/daoc").then(res=>{
        xiala.value=res.data
    })
}
const weixiu=(a:any)=>{
    if(!confirm("你确定要修改吗?"))
    {
        return;
    }
    axios.get("https://localhost:7292/api/Room/UptWX",{params:{id:a}}).then(res=>{
        if(res.data=1)
        {
            alert("修改成功");
            xians();
        }
        else
        {
            alert("修改失败");
        }
    })
}
const qiy=(a:any)=>{
    if(!confirm("你确定要修改吗?"))
    {
        return;
    }
    axios.get("https://localhost:7292/api/Room/UptQY",{params:{id:a}}).then(res=>{
        if(res.data=1)
        {
            alert("修改成功");
            xians();
        }
        else
        {
            alert("修改失败");
        }
    })
}
const xiugai=(a:any)=>{
    if(!confirm("你确定要修改吗?"))
    {
        return;
    }
    axios.get("https://localhost:7292/api/Room/UptHH",{params:{id:a}}).then(res=>{
        if(res.data=1)
        {
            alert("修改成功");
            xians();
        }
        else
        {
            alert("修改失败");
        }
    })
}
</script>

<style scoped>

</style>